﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinCalcManager;
using Infragistics.Win.CalcEngine;
using Infragistics.Excel;
using BYManageInfoSystem.FeeMng.FeeRecvInvoice;
using System.Collections;
using System.Text.RegularExpressions;

namespace BYManageInfoSystem
{
    public partial class Frm_FeeBankRecvMoneyRecordTab_Pri : DockContent
    {
        private DGBY.BLL.FeeRecvMoneyAccountTab m_bllFeeRecvMoneyAccountTab = new DGBY.BLL.FeeRecvMoneyAccountTab();
        private DGBY.BLL.DG_FeeTrueReceiveLockTab m_bllDG_FeeTrueReceiveLockTab = new DGBY.BLL.DG_FeeTrueReceiveLockTab();
        private DGBY.Model.FeeBankRecvMoneyRecordTab_pri m_FeeBankRecvMoneyRecordTab_pri = new DGBY.Model.FeeBankRecvMoneyRecordTab_pri();
        private bool m_bCopyInsertFlag = false;
        Hashtable m_SQLStringList = new Hashtable();
        ArrayList m_arrayList = new ArrayList();

        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        DataSet m_dsRecvMoneyAccount = null;

        public class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
        {
            UltraGridColumn m_BaseColumn = null;
            public CustomMergedCellEvaluator(UltraGrid UltraGridTemp)
            {
                foreach (UltraGridColumn column2 in UltraGridTemp.DisplayLayout.Bands[0].Columns)
                {
                    string str = column2.Header.Caption;
                    if (str == "到帐日期及摘要")
                    {
                        m_BaseColumn = column2;
                        break;
                    }
                }
            }
            // 合并日期相同的单元格（无需时间精确相同）
            public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column)
            {
                try
                {
                    string str1 = (string)row1.GetCellValue(m_BaseColumn);
                    string str2 = (string)row2.GetCellValue(m_BaseColumn);
                    string strTemp = str1.Substring(str1.Length - 1, 1);
                    return str1 == str2 && strTemp != "0";

                    //return true;

                }
                catch (System.Exception ex)
                {
                    //MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }


            }

        }
        private DGBY.BLL.BYCompBankCountTab m_bllBYCompBankCountTab = new DGBY.BLL.BYCompBankCountTab();
        private bool m_bHaveSetFontSize = false;
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private DGBY.BLL.FeeBankRecvMoneyRecordTab_pri m_bllFeeBankRecvMoneyRecordTab_pri = new DGBY.BLL.FeeBankRecvMoneyRecordTab_pri();
        private bool m_bInsertFlag = false;
        private int m_nDelIndex = -1;
        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllFeeBankRecvMoneyRecordTab_pri.GetFeeBankRecvMoneyRecordPriList("");
            ultraGrid1.DataSource = null;


            DataSet dsTemp = m_bllFactoryDataTab.GetList("");

            this.ultraDropDownFac.DataSource = dsTemp.Tables[0];
            this.ultraDropDownFac.DisplayMember = "工厂简称";
            this.ultraDropDownFac.ValueMember = "FactoryDataTabID";
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownFac.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns["工厂简称"].Hidden = false;

            this.ultraDropDownAccount.DataSource = m_dsRecvMoneyAccount.Tables[0];
            this.ultraDropDownAccount.DisplayMember = "收款帐户";
            this.ultraDropDownAccount.ValueMember = "FeeRecvMoneyAccountTabID";
            this.ultraDropDownAccount.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownAccount.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownAccount.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownAccount.DisplayLayout.Bands[0].Columns["收款帐户"].Hidden = false;

            ultraGrid1.DataSource = ds.Tables[0];
            ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[0].Columns[2].Hidden = true;

            this.ultraGrid1.DisplayLayout.Bands[0].Columns["余额"].Hidden = true;
    
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["摘要"].ValueList = this.ultraDropDownFac;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["帐户名称"].ValueList = this.ultraDropDownAccount;
        }
        public Frm_FeeBankRecvMoneyRecordTab_Pri()
        {
            InitializeComponent();
        }

        private void Frm_FeeBankRecvMoneyRecordTab_Pri_Load(object sender, EventArgs e)
        {
            InitComBox();
            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);
        }

        private void InitComBox()
        {
            m_dsRecvMoneyAccount = m_bllFeeRecvMoneyAccountTab.GetList("");
            if (m_dsRecvMoneyAccount.Tables.Count > 0 && m_dsRecvMoneyAccount.Tables[0].Rows.Count > 0)
            {
                this.comboBoxRecvMoneyAccount.DataSource = m_dsRecvMoneyAccount.Tables[0];

                this.comboBoxRecvMoneyAccount.ValueMember = "FeeRecvMoneyAccountTabID";
                this.comboBoxRecvMoneyAccount.DisplayMember = "收款帐户";
                this.comboBoxRecvMoneyAccount.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxRecvMoneyAccount.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxRecvMoneyAccount.SelectedIndex = 0;
            }
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecord("");
        }

        private void toolStripMenuItemAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.textBoxYearMonth.Text == "")
                {
                    MessageBox.Show("请设置实收费用计提年月", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!m_bInsertFlag)
                {
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }

            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

        }
        private bool CopyAddGoodsDetail(int nRowIndex)
        {

            try
            {

                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_pri = new DGBY.Model.FeeBankRecvMoneyRecordTab_pri();


                modelFeeBankRecvMoneyRecordTab_pri = m_FeeBankRecvMoneyRecordTab_pri;
                
                modelFeeBankRecvMoneyRecordTab_pri.ShouldRecvYearMonth = Convert.ToInt32(CurrentUGR.Cells["所属应收费用年月"].Value.ToString(), 10);

                modelFeeBankRecvMoneyRecordTab_pri.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["摘要"].Value.ToString(), 10);
                modelFeeBankRecvMoneyRecordTab_pri.RecvMoneyJinE = Convert.ToDecimal(CurrentUGR.Cells["实收金额"].Value.ToString());//原币金额公式
                modelFeeBankRecvMoneyRecordTab_pri.OuputJinE = Convert.ToDecimal(CurrentUGR.Cells["支出"].Value.ToString());//原币金额公式
                modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 = Convert.ToBoolean(CurrentUGR.Cells["是否合并"].Value.ToString());
                modelFeeBankRecvMoneyRecordTab_pri.Note = "";

                modelFeeBankRecvMoneyRecordTab_pri.datetimeFiledReserv1 = System.DateTime.Now.Date;
                modelFeeBankRecvMoneyRecordTab_pri.decimalFiledReserv1 = 0;
                modelFeeBankRecvMoneyRecordTab_pri.stringFiledReserv1 = "";
                modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1 = Convert.ToInt32(CurrentUGR.Cells["序号"].Value.ToString(), 10);
                modelFeeBankRecvMoneyRecordTab_pri.FeeRecvMoneyAccountTabID = 1;
                //modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 = false;
                int nId = m_bllFeeBankRecvMoneyRecordTab_pri.Add(modelFeeBankRecvMoneyRecordTab_pri);

                ShowAllRecord("");

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {

                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_pri = new DGBY.Model.FeeBankRecvMoneyRecordTab_pri();

                DateTime dtTemp = Convert.ToDateTime(CurrentUGR.Cells["到帐日期"].Value.ToString());

                modelFeeBankRecvMoneyRecordTab_pri.DaoZhangDate = dtTemp.Date;
                modelFeeBankRecvMoneyRecordTab_pri.ShouldRecvYearMonth = Convert.ToInt32(CurrentUGR.Cells["所属应收费用年月"].Value.ToString(), 10);

                modelFeeBankRecvMoneyRecordTab_pri.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["摘要"].Value.ToString(), 10);
                modelFeeBankRecvMoneyRecordTab_pri.RecvMoneyJinE = Convert.ToDecimal(CurrentUGR.Cells["实收金额"].Value.ToString());//原币金额公式
                modelFeeBankRecvMoneyRecordTab_pri.OuputJinE = Convert.ToDecimal(CurrentUGR.Cells["支出"].Value.ToString());//原币金额公式
                modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 = Convert.ToBoolean(CurrentUGR.Cells["是否合并"].Value.ToString());
                modelFeeBankRecvMoneyRecordTab_pri.Note = "";

                modelFeeBankRecvMoneyRecordTab_pri.datetimeFiledReserv1 = System.DateTime.Now.Date;
                modelFeeBankRecvMoneyRecordTab_pri.decimalFiledReserv1 = 0;
                modelFeeBankRecvMoneyRecordTab_pri.stringFiledReserv1 = "";
                modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1 = Convert.ToInt32(CurrentUGR.Cells["序号"].Value.ToString(), 10);
                modelFeeBankRecvMoneyRecordTab_pri.FeeRecvMoneyAccountTabID = 1;
                modelFeeBankRecvMoneyRecordTab_pri.FeeTrueReciveveDate = Convert.ToInt32(this.textBoxYearMonth.Text);
                //modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 = false;
                int nId = m_bllFeeBankRecvMoneyRecordTab_pri.Add(modelFeeBankRecvMoneyRecordTab_pri);

                ShowAllRecord("");

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void InitNewAddRowValueCopyContract(int nIndex)
        {

            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
            //  CurrentUGR.Cells["单据日期"].Value = DateTime.Now.Date;
            CurrentUGR.Cells["到帐日期"].Value = m_FeeBankRecvMoneyRecordTab_pri.DaoZhangDate;
            CurrentUGR.Cells["所属应收费用年月"].Value = 0;
            CurrentUGR.Cells["实收金额"].Value = 0;
            CurrentUGR.Cells["支出"].Value = 0;
            CurrentUGR.Cells["摘要"].Value = m_FeeBankRecvMoneyRecordTab_pri.FactoryDataTabID;
            CurrentUGR.Cells["序号"].Value = m_FeeBankRecvMoneyRecordTab_pri.stringFiledReserv1;
            CurrentUGR.Cells["是否合并"].Value = m_FeeBankRecvMoneyRecordTab_pri.bitFiledReserv1;
            CurrentUGR.Cells["实收费用计提年月"].Value = m_FeeBankRecvMoneyRecordTab_pri.FeeTrueReciveveDate;

            if (m_bCopyInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[2].Activation = Activation.ActivateOnly;
                m_bCopyInsertFlag = false;
                CopyAddGoodsDetail(nIndex);

            }
        }
        private void InitNewAddRowValue(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
            //  CurrentUGR.Cells["单据日期"].Value = DateTime.Now.Date;
            CurrentUGR.Cells["到帐日期"].Value = DateTime.Now.Date;
            CurrentUGR.Cells["所属应收费用年月"].Value = 0;
            CurrentUGR.Cells["实收金额"].Value = 0;
            CurrentUGR.Cells["支出"].Value = 0;
            CurrentUGR.Cells["摘要"].Value = 297;
            DataSet ds = m_bllFeeBankRecvMoneyRecordTab_pri.GetMaxNo();
            if (ds.Tables[0].Rows[0]["maxNo"].ToString() != "")
            {
                CurrentUGR.Cells["序号"].Value = (int)ds.Tables[0].Rows[0]["maxNo"];
            }
            else
            {
                CurrentUGR.Cells["序号"].Value = 1;
            }
            CurrentUGR.Cells["是否合并"].Value = false;
            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[2].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }
        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.StartsWith;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);

            //   UltraGridBand band = e.Layout.Bands[0];
            //   band.ColumnFilters["原币金额"].FilterConditions.Clear();
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.GreaterThan, 5);
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.LessThan, 10);
            //   band.ColumnFilters["原币金额"].LogicalOperator = FilterLogicalOperator.And;
        }

        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);

            SummarySettings averageSummary =
       e.Layout.Bands[0].Summaries.Add(
       "实收金额",
       SummaryType.Sum,
       e.Layout.Bands[0].Columns["实收金额"]);
            averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
            averageSummary.SummaryPositionColumn = averageSummary.SourceColumn;
            averageSummary.DisplayFormat = "{0:.##}";
            averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;
            averageSummary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;

            averageSummary =
 e.Layout.Bands[0].Summaries.Add(
 "实收金额合计",
 SummaryType.Sum,
 e.Layout.Bands[0].Columns["实收金额"]);
            averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
            averageSummary.SummaryPositionColumn = e.Layout.Bands[0].Columns["实收金额合计"];
            averageSummary.DisplayFormat = "{0:.##}";
            averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;
            averageSummary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;

            averageSummary =
e.Layout.Bands[0].Summaries.Add(
"支出",
SummaryType.Sum,
e.Layout.Bands[0].Columns["支出"]);
            averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
            averageSummary.SummaryPositionColumn = averageSummary.SourceColumn;
            averageSummary.DisplayFormat = "{0:.##}";
            averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;
            averageSummary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;
        }

        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);


            if (m_bCopyInsertFlag == false)
            {
                m_bInsertFlag = true;
                InitNewAddRowValue(e.Row.Index);
            }
            else
            {
                m_bCopyInsertFlag = true;
                InitNewAddRowValueCopyContract(e.Row.Index);
                
            }
            
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;
        }
        private bool ModifyGoodsDetail(int nRowIndex)
        {
            try
            {

                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                string strTempYear = CurrentUGR.Cells["实收费用计提年月"].Value.ToString();
                if (strTempYear == "")
                {
                    MessageBox.Show("实收费用计提年月未赋值！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                bool bRet = CheckTrueReceiveModify(CurrentUGR);
                if (!bRet)
                {
                    MessageBox.Show("费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }

                int nSelectFeeBankRecvMoneyRecordTab_priID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_pri = m_bllFeeBankRecvMoneyRecordTab_pri.GetModel(nSelectFeeBankRecvMoneyRecordTab_priID);


                bool bOld = modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1;

                DateTime dtTemp = Convert.ToDateTime(CurrentUGR.Cells["到帐日期"].Value.ToString());

                modelFeeBankRecvMoneyRecordTab_pri.DaoZhangDate = dtTemp.Date;
                modelFeeBankRecvMoneyRecordTab_pri.ShouldRecvYearMonth = Convert.ToInt32(CurrentUGR.Cells["所属应收费用年月"].Value.ToString(), 10);

                //modelFeeBankRecvMoneyRecordTab_pri.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["摘要"].Value.ToString(), 10);
                modelFeeBankRecvMoneyRecordTab_pri.RecvMoneyJinE = Convert.ToDecimal(CurrentUGR.Cells["实收金额"].Value.ToString());//原币金额公式
                modelFeeBankRecvMoneyRecordTab_pri.Note = CurrentUGR.Cells["备注"].Value.ToString();
                modelFeeBankRecvMoneyRecordTab_pri.OuputJinE = Convert.ToDecimal(CurrentUGR.Cells["支出"].Value.ToString());
                modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 = Convert.ToBoolean(CurrentUGR.Cells["是否合并"].Value.ToString());


                string strBGH = CurrentUGR.Cells["摘要"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelFeeBankRecvMoneyRecordTab_pri.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["摘要"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllFactoryDataTab.GetList("FactoryNameJX = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelFeeBankRecvMoneyRecordTab_pri.FactoryDataTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["FactoryDataTabID"].ToString(), 10);
                    }
                }
                string strTemp = dtTemp.Year.ToString().Substring(2, 2) + "." + dtTemp.Month.ToString().PadLeft(2, '0') + "." + dtTemp.Day.ToString() + CurrentUGR.Cells["摘要"].Text + (modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 ? "1" : "0");
                //CurrentUGR.Cells["到帐日期及摘要"].Value = strTemp;
                if (nRowIndex > 0)
                {
                    //UltraGridRow PreUGR = ultraGrid1.Rows[nRowIndex - 1];
                    //string strPrevTemp = PreUGR.Cells["到帐日期及摘要除去序号"].Value.ToString();

                    //if (strPrevTemp == strTemp)
                    //{
                    //    modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1 = Convert.ToInt32(PreUGR.Cells["序号"].Value.ToString(), 10);

                    //}
                    //else
                    {
                        modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1 = Convert.ToInt32(CurrentUGR.Cells["序号"].Value.ToString(), 10);

                    }
                    //如果原来是合并的，现在变成不合并了
                    //if (bOld == true && modelFeeBankRecvMoneyRecordTab_pri.bitFiledReserv1 != true)
                    //{
                    //    DataSet ds = m_bllFeeBankRecvMoneyRecordTab_pri.GetMaxNo();
                    //    if (ds.Tables[0].Rows[0]["maxNo"].ToString() != "")
                    //    {
                    //        CurrentUGR.Cells["序号"].Value = (int)ds.Tables[0].Rows[0]["maxNo"];
                    //        modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["maxNo"];
                    //    }
                    //}
                    //else
                    {
                        CurrentUGR.Cells["序号"].Value = modelFeeBankRecvMoneyRecordTab_pri.intFiledReserv1;
                    }
               
                }

                string strAccount = CurrentUGR.Cells["帐户名称"].Value.ToString();
                if (ClassInputValid.IsNum(strAccount))
                {
                    modelFeeBankRecvMoneyRecordTab_pri.FeeRecvMoneyAccountTabID = Convert.ToInt32(CurrentUGR.Cells["帐户名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllFeeRecvMoneyAccountTab.GetList("FeeRecvMoneyAccountName = '" + strAccount + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelFeeBankRecvMoneyRecordTab_pri.FeeRecvMoneyAccountTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["FeeRecvMoneyAccountTabID"].ToString(), 10);
                    }
                }

                modelFeeBankRecvMoneyRecordTab_pri.FeeTrueReciveveDate = Convert.ToInt32(CurrentUGR.Cells["实收费用计提年月"].Value.ToString(), 10);
                m_bllFeeBankRecvMoneyRecordTab_pri.Update(modelFeeBankRecvMoneyRecordTab_pri);

                //string strTemp = dtTemp.Year.ToString() + dtTemp.Month.ToString().PadLeft(2, '0') + dtTemp.Day.ToString() + strBGH;
                //CurrentUGR.Cells["到帐日期及摘要"].Value = strTemp;
                ShowAllRecord("");
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;



                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
        {
            ultraGrid1.DisplayLayout.Override.CellAppearance.TextHAlign = HAlign.Center;
            ultraGrid1.DisplayLayout.Override.CellAppearance.TextVAlign = VAlign.Middle;
            ultraGrid1.DisplayLayout.Override.MergedCellAppearance.TextHAlign = HAlign.Center;
            ultraGrid1.DisplayLayout.Override.MergedCellAppearance.TextVAlign = VAlign.Middle;

            ultraGrid1.DisplayLayout.Bands[0].Columns["序号"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["序号"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["是否合并"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否合并"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["到帐日期"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["到帐日期"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
            ultraGrid1.DisplayLayout.Bands[0].Columns["摘要"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["摘要"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
            ultraGrid1.DisplayLayout.Bands[0].Columns["实收金额合计"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实收金额合计"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);

            ultraGrid1.DisplayLayout.Bands[0].Columns["支出"].MergedCellStyle = MergedCellStyle.Always;
            ultraGrid1.DisplayLayout.Bands[0].Columns["支出"].MergedCellEvaluator = new
   CustomMergedCellEvaluator(this.ultraGrid1);
            
            //ultraGrid1.DisplayLayout.Bands[0].Columns["支出"].MergedCellEvaluationType = MergedCellEvaluationType

   //         ultraGrid1.DisplayLayout.Bands[0].Columns["余额"].MergedCellStyle = MergedCellStyle.Always;
   //         ultraGrid1.DisplayLayout.Bands[0].Columns["余额"].MergedCellEvaluator = new
   //CustomMergedCellEvaluator(this.ultraGrid1);

            if (!m_bHaveSetFontSize)
            {
                ultraGrid1.DisplayLayout.Override.HeaderAppearance.FontData.SizeInPoints = 12;
                ultraGrid1.DisplayLayout.Override.CellAppearance.FontData.SizeInPoints = 12;
                m_bHaveSetFontSize = true;
            }
        }

        private void 删除该行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid1.ActiveRow != null)
                {
                    UltraGridRow CurrentUGR;
                    CurrentUGR = ultraGrid1.Rows[nIndex];
                    int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);

                    bool bRet = CheckTrueReceiveModify(CurrentUGR);
                    if (!bRet)
                    {
                        MessageBox.Show("费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFeeBankRecvMoneyRecordTab_priID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_pri = m_bllFeeBankRecvMoneyRecordTab_pri.GetModel(nSelectFeeBankRecvMoneyRecordTab_priID);

                if (modelFeeBankRecvMoneyRecordTab_pri == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllFeeBankRecvMoneyRecordTab_pri.Delete(nSelectFeeBankRecvMoneyRecordTab_priID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns[4].Hidden = true;
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
            ultraGrid1.DisplayLayout.Bands[0].Columns[4].Hidden = false;
        }

        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {
                if (this.textBoxYearMonth.Text == "")
                {
                    MessageBox.Show("请设置实收费用计提年月", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!m_bInsertFlag)
                {
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        if (strTemp == "摘要")
                            return;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        if (strTemp == "摘要")
                            return;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ultraGridExcelExporter1_CellExported(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.CellExportedEventArgs e)
        {
            // Get the cell being exporter
            UltraGridCell cell = e.GridRow.Cells[e.GridColumn];

            // Get the Merged cells. 
            UltraGridCell[] mergedCells = cell.GetMergedCells();


            // Check to see if there are any merged cells. If not, we don't need to do anything. 
            if (mergedCells != null)
            {
                // There are merged cells. Check to see if the cell being exported is the first one. 
                bool isFirstCell = true;
                foreach (UltraGridCell mergedCell in mergedCells)
                {
                    if (cell.Row.Index > mergedCell.Row.Index)
                    {
                        // If the cell being exported has a higher index that any of the cells
                        // it is merged with, them it's not the first cell and we should already
                        // have handled the merge. 
                        isFirstCell = false;
                        break;
                    }
                }

                // If it is the first cell, merge this cell with the cells below it based on the 
                // count of the merged cells. 
                if (isFirstCell)
                {
                    int rowIndex = e.CurrentRowIndex;
                    int colIndex = e.CurrentColumnIndex;
                    Infragistics.Excel.WorksheetMergedCellsRegion mergedRegion = e.CurrentWorksheet.MergedCellsRegions.Add(
                        rowIndex,
                        colIndex,
                        rowIndex + (mergedCells.Length - 1),
                        colIndex);
                    mergedRegion.CellFormat.Alignment = Infragistics.Excel.HorizontalCellAlignment.Center;
                    mergedRegion.CellFormat.VerticalAlignment = Infragistics.Excel.VerticalCellAlignment.Center;
                }

            }
        }

        private void ultraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e)
        {
            Worksheet ws = e.CurrentWorksheet;

            ws.Rows[0].Cells[2].CellFormat.Alignment = Infragistics.Excel.HorizontalCellAlignment.Center;

            ws.Rows[0].Cells[2].CellFormat.Font.Height = 400;



            ws.Rows[0].Cells[2].Value = "私帐收款明细";


            DGBY.Model.BYCompBankCountTab modelBYCompBankCountTabPri = new DGBY.Model.BYCompBankCountTab();
            //DGBY.Model.BYCompBankCountTab modelBYCompBankCountTabPri = new DGBY.Model.BYCompBankCountTab();
            DataSet ds = m_bllBYCompBankCountTab.GetAllAccountInfo();
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int nID = Convert.ToInt32(ds.Tables[0].Rows[i]["BYCompBankCountTabID"].ToString(), 10);
                    string strComp = ds.Tables[0].Rows[i]["经营单位名称"].ToString();
                    //if (strComp == "")
                    //    modelBYCompBankCountTabPri = m_bllBYCompBankCountTab.GetModel(nID);
                    if (strComp == "")
                        modelBYCompBankCountTabPri = m_bllBYCompBankCountTab.GetModel(nID);
                }
            }


            int a = 1;
            ws.Rows[a].CellFormat.Font.Height = 300;

            ws.Rows[a].Cells[0].Value = "收款帐户：";

            ws.Rows[a].Cells[1].Value = "开户名：" + modelBYCompBankCountTabPri.CountName
                + " 开户行：" + modelBYCompBankCountTabPri.KHBank
                + " 帐号：" + modelBYCompBankCountTabPri.CountNo;


            e.CurrentRowIndex = 3;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Frm_FeeRecvMoneyAccountTab frm_FeeRecvMoneyAccountTab = new Frm_FeeRecvMoneyAccountTab();
            frm_FeeRecvMoneyAccountTab.StartPosition = FormStartPosition.CenterScreen;
            frm_FeeRecvMoneyAccountTab.ShowDialog();

            InitComBox();
        }

        private void buttonBatchModRecvMoneyP_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {
                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();


                for (int i = 0; i < ugr.Length; i++)
                {

                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_priOld
                                        = m_bllFeeBankRecvMoneyRecordTab_pri.GetModel(nID);
                    modelFeeBankRecvMoneyRecordTab_priOld.FeeRecvMoneyAccountTabID = Convert.ToInt32(this.comboBoxRecvMoneyAccount.SelectedValue);
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];

                    m_bllFeeBankRecvMoneyRecordTab_pri.TransUpdate(modelFeeBankRecvMoneyRecordTab_priOld
                        , m_SQLStringList, m_arrayList, i);
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量修改收款帐户", this.comboBoxRecvMoneyAccount.Text);
                MessageBox.Show("批量修改收款帐户完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void buttonBatchModifyDate_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {
                if (!ClassInputValid.IsNum(textBoxYearMonth.Text))
                {
                    errorProvider1.SetError(textBoxYearMonth, "必须输入数字");
                    return;
                }

                int nYearMon = Convert.ToInt32(textBoxYearMonth.Text, 10);
                if (nYearMon < 201001 || nYearMon > 219912)
                {
                    errorProvider1.SetError(textBoxYearMonth, "必须正确的年月，形如201206");
                    return;
                }

                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();

                DialogResult dr = MessageBox.Show("确实要批量修改以下" + ugr.Length.ToString() + "条记录的实收费用计提年月么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (dr == DialogResult.Cancel)
                    return;

                for (int i = 0; i < ugr.Length; i++)
                {

                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeBankRecvMoneyRecordTab_pri modelFeeBankRecvMoneyRecordTab_priOld
                                        = m_bllFeeBankRecvMoneyRecordTab_pri.GetModel(nID);
                    modelFeeBankRecvMoneyRecordTab_priOld.FeeTrueReciveveDate = nYearMon;
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];

                    m_bllFeeBankRecvMoneyRecordTab_pri.TransUpdate(modelFeeBankRecvMoneyRecordTab_priOld
                        , m_SQLStringList, m_arrayList, i);
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量实收费用计提年月", nYearMon.ToString());
                MessageBox.Show("批量实收费用计提年月完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private bool CheckTrueReceiveModify(UltraGridRow CurrentUGR)
        {
            if ("" != CurrentUGR.Cells["实收费用计提年月"].Value.ToString())
            {
                int nYearMonth = Convert.ToInt32(CurrentUGR.Cells["实收费用计提年月"].Value.ToString(), 10);
                DataSet ds = m_bllDG_FeeTrueReceiveLockTab.GetList("IsLock = 1 and LockYearMonth = '" + nYearMonth.ToString() + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return false;
                }
            }
            return true;
        }

        private void 复制增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (!m_bCopyInsertFlag)
                {
                    UltraGridRow CurrentUGRFrom;
                    CurrentUGRFrom = ultraGrid1.Rows[m_nDelIndex];
                    int nSelectFeeSJTruePayTabID = Convert.ToInt32(CurrentUGRFrom.Cells[0].Value.ToString(), 10);


                    m_FeeBankRecvMoneyRecordTab_pri = m_bllFeeBankRecvMoneyRecordTab_pri.GetModel(nSelectFeeSJTruePayTabID);
                    m_FeeBankRecvMoneyRecordTab_pri.stringFiledReserv1 = CurrentUGRFrom.Cells["序号"].Value.ToString();
                    m_bCopyInsertFlag = true;
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //m_InsertType = InsertType.Common;
                    //AddNewRow();

                }
            }
            catch
            {
                m_bCopyInsertFlag = false;
                MessageBox.Show("没有选择记录，无法复制！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
